package com.handsome.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.handsome.entity.HsMenu;
import com.handsome.service.AuthService;
import com.handsome.utils.JsonUtil;
import com.handsome.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class AuthController extends BaseController {

    @Autowired
    private AuthService authService;

    @RequestMapping("/auth/index")
    public String index(Model model) {
        try {
            model.addAttribute("menus", new ObjectMapper().writeValueAsString(authService.getMenus(false)));
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
        return "auth/index";
    }


    @PostMapping("/auth/add_menu")
    @ResponseBody
    public Result actionMenu(HsMenu menu) {

        return authService.actionMenu(menu);
    }




}
